package com.shopping.orm;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class OrderFormDao extends HibernateDaoSupport {

	private static final Log log = LogFactory.getLog(OrderFormDao.class);
	public void save(OrderForm instance){
		log.debug("saving OrderForm instance");
		try{
		getHibernateTemplate().save(instance);
		log.debug("save OrderForm successful");
		}catch(RuntimeException re){
			log.error("save OrderForm failed",re);
			throw re;
		}
	}
	
	public void delete(OrderForm instance) {
        log.debug("deleting OrderForm instance");
        try {
            getHibernateTemplate().delete(instance);
            log.debug("delete OrderForm instance successful");
        } catch (RuntimeException re) {
            log.error("delete OrderForm instance failed", re);
            throw re;
        }
    }
	
	public void update(OrderForm instance){
		log.debug("Upate OrderForm instance");
		try{
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("update OrderForm instance  successful");
			
		}catch(RuntimeException re){
			log.error("update OrderForm instance failed",re);
			throw re;
		}
	}
	public List findByExample(OrderForm instance){
		log.debug("get OrderForm instance with +:example");
		try{
			List result = getHibernateTemplate().findByExample(instance);
			log.debug("get successful!");
			return result;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}
	}
	
	public List findByproperty(String propertyName,Object value){
		log.debug("finding OrderForm instance with property:"+ propertyName + ",value:"+value);
		try {
		    String queryString = "from OrderForm as model where model." 
		         						+ propertyName + "= ?";
		    return getHibernateTemplate().find(queryString, value);
		}catch(RuntimeException re){
			log.error("find by property failed",re);
			throw re;
		}
	}
	
	
	public List findAll(){
		log.debug("getting OrderForm instance");		
		try{
			List result = getHibernateTemplate().findByExample("OrderForm");
			log.debug("find successful!");
			return result;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}
	}
	
	
	public OrderForm findById(String uid){
		log.debug("get OrderForm instance with id:+uid");
		try{
			OrderForm instance = (OrderForm)getHibernateTemplate().get("OrderForm", uid);
			log.debug("get successful!");
			return instance;
		}catch(RuntimeException re){
			log.error("get failed",re);
			throw re;
		}	
	}
}
